﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;

namespace PM.Web
{
    public partial class Index : System.Web.UI.Page
    {
        public string picandlinks = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                checkpermission();
                bindData();
            }
        }

        private void checkpermission()
        {
            if (Session["EmpId"] != null)
            {
                bindChamber();
                this.lbltips.Visible = false;
                this.repRepairAndComp.Visible = true;
            }
            else
            {
                this.lbltips.Visible = true;
                this.repRepairAndComp.Visible = false;
            }
        }

        private void bindData()
        {
            System.Text.StringBuilder pics = new System.Text.StringBuilder();
            System.Text.StringBuilder links = new System.Text.StringBuilder();
            pics.Append("pics="); links.Append("&links="); string sper = "|";
            DataAccess.PmData dal = new DataAccess.PmData();
            DataTable dt = dal.GetWebSiteNewsPic(1, null, 5);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i == dt.Rows.Count - 1) sper = string.Empty;
                pics.Append(dt.Rows[i]["TitlePic"].ToString()).Append(sper);
                links.Append("NewsDetail.aspx?id=" + dt.Rows[i]["NewsId"].ToString()).Append(sper);
            }
            picandlinks = pics.ToString() + links.ToString();


            dt = dal.GetWebSiteNewsList(Common.GetCommunityCode(), null, null, 8);
            this.repNewsList.DataSource = dt;
            this.repNewsList.DataBind();


            this.repTopicTZList.DataSource = dal.GetTopicList(Common.GetCommunityCode(), null, 1, "社区通知", 8);
            this.repTopicTZList.DataBind();

            this.repTopicHDList.DataSource = dal.GetTopicList(Common.GetCommunityCode(), null, 1, "活动召集", 8);
            this.repTopicHDList.DataBind();

            this.repTopicYAList.DataSource = dal.GetTopicList(Common.GetCommunityCode(), null, 2, "社区议题", 8);
            this.repTopicYAList.DataBind();

        }

        private void bindChamber()
        {
            DataAccess.PmData dal = new DataAccess.PmData();
            this.repRepairAndComp.DataSource = dal.GetRepairAndComplaints(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()), int.Parse(Session["EmpId"].ToString()), string.Empty, 8);
            this.repRepairAndComp.DataBind();
        }
    }
}